import request from '../utils/request';

// 获取用户信息
export function getUserInfo() {
  return request({
    url: '/user/profile',
    method: 'get'
  });
}

// 更新用户信息
export function updateUserInfo(data) {
  return request({
    url: '/user/profile',
    method: 'put',
    data
  });
}

// 上传头像
export function uploadAvatar(file) {
  console.log('📤 准备上传头像文件:', {
    name: file.name,
    size: file.size,
    type: file.type
  });

  const formData = new FormData();
  formData.append('avatar', file);

  console.log('📤 FormData 创建完成，开始发送请求...');

  return request({
    url: '/user/avatar',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

// 修改密码
export function changePassword(data) {
  return request({
    url: '/user/password',
    method: 'put',
    data
  });
}

// 获取用户设置
export function getUserSettings() {
  return request({
    url: '/user/settings',
    method: 'get'
  });
}

// 更新用户设置
export function updateUserSettings(data) {
  return request({
    url: '/user/settings',
    method: 'put',
    data
  });
}

// 账户充值
export function rechargeBalance(data) {
  return request({
    url: '/user/recharge',
    method: 'post',
    data
  });
}

// 获取充值记录
export function getRechargeHistory(params) {
  return request({
    url: '/user/recharge/history',
    method: 'get',
    params
  });
}

// 获取用户余额
export function getUserBalance() {
  return request({
    url: '/user/balance',
    method: 'get'
  });
}
